<?php 
namespace Gigasweb\Wordpress\Metabox;
class PostParent {
	private $_PostType;
	private $_Title;
	private $_Tip;
	private $_Name;
	private $_ParentPost;
	private $_MimeType;
	
	function __construct( $params ) {
		$defaults = array(
				'title' => '',
				'name' => '',
				'tip' => '',
				'post_type' => 'post',
				'parent_post' => 0,
				'mime_type' => ''
		);
		$params = array_merge( $defaults, $params );
		
		$this->_PostType = $params['post_type'];
		$this->_Title = $params['title'];
		$this->_Tip = $params['tip'];
		$this->_Name = $params['name'];
		$this->_ParentPost = $params['parent_post'];
		$this->_MimeType = $params['mime_type'];
	}
	
	public function Render( $selected = '') {
		$posts = get_posts( array( 
				'post_parent' => $this->_ParentPost, 
				'post_type' => $this->_PostType, 
				'numberposts' => -1,
				'posts_per_apge' => -1, 
				'post_status' => 'any',
				'post_mime_type' => $this->_MimeType 
			) );
		?>
	    <div class="inside">
	        <p><strong><?php echo $this->_Title; ?></strong></p>
	        <select name="<?php echo $this->_Name; ?>" id="id_<?php echo $this->_PostType; ?>">
	            <option value=""><?php echo $this->_Tip; ?></option>
	        <?php foreach( $posts as $d ) { ?>	
	            <option class="value"<?php if( $selected == $d->ID ) { ?> selected="selected" <? } ?>value="<?php echo $d->ID; ?>"><?php echo $d->post_title; ?></option>	
	        <?php } ?>
	        </select>
		</div>
		<?php
	}
}